import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from './router'
import store from './store/'
import {VueAxios} from '@/utils/request'
import AntD from 'ant-design-vue'
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

import * as echarts from 'echarts'
import processingConditionsAll from './components/processing-conditions/processing-conditions-all'
import handlingOpinions from '@/components/handling-opinions/handling-opinions'
import handlingOpinionsVisual from '@/components/handling-opinions/handling-opinions-visual'
import selectInspectionBasis from '@/components/handling-opinions/select-inspectionBasis'
import selectTemplate from '@/components/selectTemplate/selectTemplate'
import supplementaryRectification from './components/supplementary-rectification/supplementary-rectification.vue'
import supplementaryHistory from './components/supplementary-rectification/supplementary-history.vue'
import partTimeSituation from './components/partTimeSituation/partTimeSituation.vue'
import commpStep from './components/commp-step/commpStep.vue'
import VueClipboard from 'vue-clipboard2'
import { AddWatermarkHandle } from '@/common/watermark.js'
//
//
// import './global.less' // 功能与后加载的color.less重复
import 'ant-design-vue/dist/antd.less'
import {
  LANGUAGE_CODE,
  DEFAULT_COLOR,
  DEFAULT_THEME,
  DEFAULT_LAYOUT_MODE,
  DEFAULT_COLOR_WEAK,
  SIDEBAR_TYPE,
  DEFAULT_FIXED_HEADER,
  DEFAULT_FIXED_HEADER_HIDDEN,
  DEFAULT_FIXED_SIDEMENU,
  DEFAULT_CONTENT_WIDTH_TYPE,
  DEFAULT_MULTI_PAGE,
  USER_INFO,
} from '@/store/mutation-types'
import config from '@/settings'
import YchDictSelectTag from './components/dict/index.js'

import '@yuncheng/ych-components/lib/vcolorpicker.css'
import '@/assets/font_4321546_xegjs9iv7ge/iconfont.css'
import lodash from 'lodash'
import VueI18n from 'vue-i18n'
import MessageUtil from './utils/MessageUtil'
import ychCommon from './utils/common'
import hasPermission from './utils/hasPermission'
import Print from 'vue-print-nb'//打印

import 'xe-utils'


// 默认是微前端主应用，如果是微前端入口进入，则不开启主应用
import microApp from '@micro-zoe/micro-app'
if(!window.__MICRO_APP_ENVIRONMENT__){
  microApp.start()
}
import { ShowPage } from './utils/util'
Vue.config.productionTip = false
Vue.use(VueQuillEditor)
Vue.use(Storage, config.storageOptions)
Vue.use(AntD)
Vue.use(VueAxios, router)
Vue.use(YchDictSelectTag)
Vue.use(Print)
Vue.prototype.$webOffice = ShowPage
Vue.prototype.$echarts = echarts
Vue.component('processingConditionsAll', processingConditionsAll)
Vue.component('handlingOpinions', handlingOpinions)
Vue.component('handlingOpinionsVisual', handlingOpinionsVisual)
Vue.component('selectInspectionBasis', selectInspectionBasis)


Vue.component('selectTemplate', selectTemplate)
Vue.component('supplementaryRectification', supplementaryRectification)
Vue.component('supplementaryHistory', supplementaryHistory)
Vue.component('partTimeSituation', partTimeSituation)
Vue.component('commpStep', commpStep)

import {YchModal, YchIcon} from '@yuncheng/ych-components'
Vue.use(YchModal)
Vue.use(YchIcon)
Vue.use(VueClipboard)


Vue.prototype.lodash = lodash
Vue.use(VueI18n)
Vue.prototype.messageUtil = MessageUtil
Vue.prototype.$ychCommon = ychCommon;
Vue.use(hasPermission)
Vue.prototype.$AddWatermarkHandle = AddWatermarkHandle;

import zhCN_vxe from 'vxe-table/lib/locale/lang/zh-CN'
import enUS_vxe from 'vxe-table/lib/locale/lang/en-US'
import zhCN from './assets/lang/zh_CN.json'
import enUS from './assets/lang/en_US.json'
import reviewOpinions from '@/components/handling-opinions/review-opinions'

const i18n = new VueI18n({
  locale: store.getters.language,    // 语言标识
  messages: {
    zh_CN: {
      ...zhCN, ...zhCN_vxe
    },
    en_US: {
      ...enUS, ...enUS_vxe
    }
  }
})
window.$i18n = i18n
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
VXETable.setup({
  // 对组件内置的提示语进行国际化翻译
  i18n: (key, args) => i18n.t(key, args)
})
Vue.use(VXETable)
Vue.prototype.$VXETable = VXETable
Vue.prototype.$VxeMessage = VXETable.modal.message
import { updateTheme } from '@/framework/tools/setting'
import YchConstant from "@/api/YchConstant";
import { getAction } from '@/api/manage'
Vue.prototype.$Base64 = require('js-base64').Base64
import '@/assets/less/common.less';
// 多语言
import LocaleUtil from "./utils/LocaleUtil";
Vue.prototype.$locale = LocaleUtil.getLocale;
Vue.component('reviewOpinions', reviewOpinions)

import VueKindEditor from './utils/kindeditor.js'
import '../src/assets/kindeditor/themes/default/default.css'
import '../src/assets/kindeditor/kindeditor-all-min.js'
import '../src/assets/kindeditor/lang/zh-CN.js'
Vue.use(VueKindEditor)

import TokenStorageUtil from "./utils/TokenStorageUtil";

//富文本框1
import '../public/UEditor/ueditor.config.js'
import '../public/UEditor/ueditor.all.min.js'
import '../public/UEditor/lang/zh-cn/zh-cn.js'
import '../public/UEditor/ueditor.parse.min.js'
//

window.$vm = new Vue({
  router,
  store,
  i18n,
  mounted() {
    // 多语言
    store.dispatch('setLanguage', {language: Vue.ls.get(LANGUAGE_CODE), i18n})

    store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
    store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
    store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
    store.commit('TOGGLE_FIXED_HEADER', Vue.ls.get(DEFAULT_FIXED_HEADER, config.fixedHeader))
    store.commit('TOGGLE_FIXED_SIDERBAR', Vue.ls.get(DEFAULT_FIXED_SIDEMENU, config.fixSiderbar))
    store.commit('TOGGLE_CONTENT_WIDTH', Vue.ls.get(DEFAULT_CONTENT_WIDTH_TYPE, config.contentWidth))
    store.commit('TOGGLE_FIXED_HEADER_HIDDEN', Vue.ls.get(DEFAULT_FIXED_HEADER_HIDDEN, config.autoHideHeader))
    store.commit('TOGGLE_WEAK', Vue.ls.get(DEFAULT_COLOR_WEAK, config.colorWeak))
    store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
    store.commit('SET_TOKEN', TokenStorageUtil.get())
    store.commit('SET_INFO', Vue.ls.get(USER_INFO))
    store.commit('SET_MULTI_PAGE', Vue.ls.get(DEFAULT_MULTI_PAGE, config.multipage))

    // insert less.js and color.less
    const lessStyleNode = document.createElement('link');
    const lessConfigNode = document.createElement('script');
    const lessScriptNode = document.createElement('script');
    lessStyleNode.setAttribute('rel', 'stylesheet/less');
    lessStyleNode.setAttribute('href', process.env.BASE_URL + 'color.less');
    lessConfigNode.innerHTML = `
        window.less = {
          async: true,
          env: 'production',
          javascriptEnabled: true
        };
      `;
    lessScriptNode.src = 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js';
    lessScriptNode.async = true;
    lessScriptNode.onload = () => {
      // 存在小概率不生效的问题
      let primaryColor = Vue.ls.get(DEFAULT_COLOR, config.primaryColor)
      updateTheme(primaryColor);
      lessScriptNode.onload = null;
    };
    document.body.appendChild(lessStyleNode);
    document.body.appendChild(lessConfigNode);
    document.body.appendChild(lessScriptNode);

    /**
     * 动态获取项目名称等
     * @type {string}
     */
    let full_name
    let simple_name
    let logo_url = process.env.BASE_URL + 'logo.svg'
    let favicon_url = process.env.BASE_URL + 'favicon.png'
    let querySysConfigByCodeListUrl = YchConstant.PREFIX_SYSTEM+"/sysconfig/querySysConfigByCodeList?codes=project-full-name,project-simple-name,project-logo-url"
    getAction(querySysConfigByCodeListUrl).then((res) => {
      if (res.success) {
        let result = res.result;
        for(let i=0;i<result.length;i++){
          let configCode = result[i].configCode;
          let oncfigValue = result[i].configValue;
          if(configCode == 'project-full-name'){
            full_name = oncfigValue;
          }else if(configCode == 'project-simple-name'){
            simple_name = oncfigValue;
          }else if(configCode == 'project-logo-url'){
            logo_url = oncfigValue;
            favicon_url = oncfigValue;
          }
        }
      }
    }).finally(() => {
      window._CONFIG.logo_url = logo_url
      if(simple_name){
        window._CONFIG.simply_name = simple_name
      }
      if(full_name){
        window._CONFIG.full_name = full_name
      }
      if(full_name){
        document.title = full_name;
      }
      let $favicon = document.querySelector('link[rel="icon"]');
      if ($favicon !== null) {
        $favicon.href = favicon_url;
      }
    })
  },
  render: h => h(App)
}).$mount('#app')
